package com.quasar.hpatient.module.mine_favor;

import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.quasar.hpatient.R;
import com.quasar.hpatient.bean.mine_favor.FavorBean;

import java.util.ArrayList;

import lib.quasar.base.frame.BasePresenter;
import lib.quasar.recycler.BaseLoadAdapter;
import lib.quasar.recycler.holder.RecyclerHolder;
import lib.quasar.recycler.manager.CrashLinearLayoutManager;

/**
 * description: 我 ==> 我的收藏
 * created by kalu on 2018/3/30 14:18
 */
public class FavorPresenter implements BasePresenter {

    private final ArrayList<FavorBean> mData = new ArrayList<>();

    {
        for (int i = 0; i < 9; i++) {
            FavorBean model = new FavorBean();
            mData.add(model);
        }
    }

    public void initList(FavorView view, RecyclerView recycler) {

        BaseLoadAdapter adapter = new BaseLoadAdapter<FavorBean>(mData, R.layout.activity_favor_child, R.layout.layout_recycler_load) {

            @Override
            protected void onLoad(RecyclerHolder holder, boolean isOver) {
                loadList(view, recycler);
            }

            @Override
            protected void onNext(RecyclerHolder holder, final FavorBean model, int position) {

                ImageView image = holder.getView(R.id.activity_favor_child_image);
                view.setImage(image, model.getImage());

                view.setText(holder, R.id.activity_favor_child_title, model.getTitle());
                view.setText(holder, R.id.activity_favor_child_info, model.getInfo());
                view.setText(holder, R.id.activity_favor_child_look, model.getLookCount());
                view.setText(holder, R.id.activity_favor_child_star, model.getStarCount());

                holder.itemView.setOnClickListener(v -> {
                    view.toast("" + position);
                });
            }
        };

        adapter.setNullView(recycler.getContext(), R.layout.layout_recycler_loading);
        CrashLinearLayoutManager manager = new CrashLinearLayoutManager(recycler.getContext());
        recycler.setLayoutManager(manager);
        recycler.setAdapter(adapter);
    }

    private final void loadList(FavorView view, RecyclerView recycler) {
//        for (int i = 0; i < 9; i++) {
//            FavorBean model = new FavorBean();
//            mData.add(model);
//        }
//        view.refreshList(recycler);
    }

    @Override
    public void recycler() {
        mData.clear();
    }
}
